]>
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" | |
38 | #include "common.h" | |
39 | #include "hash.h" | |
4562c604 | 40 | #include "match.h" |
212380e3 AC |
41 | #include "ircd.h" |
42 | #include "numeric.h" | |
212380e3 AC |
43 | #include "s_serv.h" |
44 | #include "s_conf.h" | |
45 | #include "s_newconf.h" | |
46 | #include "send.h" | |
47 | #include "msg.h" | |
48 | #include "parse.h" | |
49 | #include "modules.h" | |
77d3d2db | 50 | #include "logger.h" |
0b904d91 | 51 | #include "supported.h" |
212380e3 | 52 | |
428ca87b AC |
53 | static int mo_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
54 | static int me_etrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
55 | static int m_chantrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
56 | static int mo_masktrace(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
57 | |
58 | struct Message etrace_msgtab = { | |
7baa37a9 | 59 | "ETRACE", 0, 0, 0, 0, |
212380e3 AC |
60 | {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, {me_etrace, 0}, {mo_etrace, 0}} |
61 | }; | |
62 | struct Message chantrace_msgtab = { | |
7baa37a9 | 63 | "CHANTRACE", 0, 0, 0, 0, |
5807e0be | 64 | {mg_ignore, {m_chantrace, 2}, mg_ignore, mg_ignore, mg_ignore, {m_chantrace, 2}} |
212380e3 AC |
65 | }; |
66 | struct Message masktrace_msgtab = { | |
7baa37a9 | 67 | "MASKTRACE", 0, 0, 0, 0, |
212380e3 AC |
68 | {mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_masktrace, 2}} |
69 | }; | |
70 | ||
0b904d91 AC |
71 | static int |
72 | _modinit(void) | |
73 | { | |
74 | add_isupport("ETRACE", isupport_string, ""); | |
75 | ||
76 | return 0; | |
77 | } | |
78 | ||
79 | static void | |
80 | _moddeinit(void) | |
81 | { | |
82 | delete_isupport("ETRACE"); | |
83 | } | |
84 | ||
212380e3 | 85 | mapi_clist_av1 etrace_clist[] = { &etrace_msgtab, &chantrace_msgtab, &masktrace_msgtab, NULL }; |
9fd8e7cb EM |
86 | |
87 | static const char etrace_desc[] = | |
88 | "Provides enhanced tracing facilities to opers (ETRACE, CHANTRACE, and MASKTRACE)"; | |
89 | ||
90 | DECLARE_MODULE_AV2(etrace, _modinit, _moddeinit, etrace_clist, NULL, NULL, NULL, NULL, etrace_desc); | |
212380e3 AC |
91 | |
92 | static void do_etrace(struct Client *source_p, int ipv4, int ipv6); | |
93 | static void do_etrace_full(struct Client *source_p); | |
94 | static void do_single_etrace(struct Client *source_p, struct Client *target_p); | |
95 | ||
96 | static const char *empty_sockhost = "255.255.255.255"; | |
97 | static const char *spoofed_sockhost = "0"; | |
98 | ||
99 | /* | |
100 | * m_etrace | |
212380e3 AC |
101 | * parv[1] = options [or target] |
102 | * parv[2] = [target] | |
103 | */ | |
104 | static int | |
428ca87b | 105 | mo_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
106 | { |
107 | if(parc > 1 && !EmptyString(parv[1])) | |
108 | { | |
109 | if(!irccmp(parv[1], "-full")) | |
110 | do_etrace_full(source_p); | |
ccda6e3f | 111 | #ifdef RB_IPV6 |
212380e3 AC |
112 | else if(!irccmp(parv[1], "-v6")) |
113 | do_etrace(source_p, 0, 1); | |
114 | else if(!irccmp(parv[1], "-v4")) | |
115 | do_etrace(source_p, 1, 0); | |
116 | #endif | |
117 | else | |
118 | { | |
119 | struct Client *target_p = find_named_person(parv[1]); | |
120 | ||
121 | if(target_p) | |
122 | { | |
123 | if(!MyClient(target_p)) | |
124 | sendto_one(target_p, ":%s ENCAP %s ETRACE %s", | |
125 | get_id(source_p, target_p), | |
c88cdb00 | 126 | target_p->servptr->name, |
212380e3 AC |
127 | get_id(target_p, target_p)); |
128 | else | |
129 | do_single_etrace(source_p, target_p); | |
130 | } | |
131 | else | |
132 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
133 | form_str(ERR_NOSUCHNICK), parv[1]); | |
134 | } | |
135 | } | |
136 | else | |
137 | do_etrace(source_p, 1, 1); | |
138 | ||
139 | return 0; | |
140 | } | |
141 | ||
142 | static int | |
428ca87b | 143 | me_etrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
144 | { |
145 | struct Client *target_p; | |
146 | ||
147 | if(!IsOper(source_p) || parc < 2 || EmptyString(parv[1])) | |
148 | return 0; | |
149 | ||
150 | /* we cant etrace remote clients.. we shouldnt even get sent them */ | |
151 | if((target_p = find_person(parv[1])) && MyClient(target_p)) | |
152 | do_single_etrace(source_p, target_p); | |
153 | ||
55abcbb2 | 154 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), |
212380e3 AC |
155 | target_p ? target_p->name : parv[1]); |
156 | ||
157 | return 0; | |
158 | } | |
159 | ||
160 | static void | |
161 | do_etrace(struct Client *source_p, int ipv4, int ipv6) | |
162 | { | |
163 | struct Client *target_p; | |
5b96d9a6 | 164 | rb_dlink_node *ptr; |
212380e3 AC |
165 | |
166 | /* report all direct connections */ | |
5b96d9a6 | 167 | RB_DLINK_FOREACH(ptr, lclient_list.head) |
212380e3 AC |
168 | { |
169 | target_p = ptr->data; | |
170 | ||
ccda6e3f | 171 | #ifdef RB_IPV6 |
212380e3 AC |
172 | if((!ipv4 && target_p->localClient->ip.ss_family == AF_INET) || |
173 | (!ipv6 && target_p->localClient->ip.ss_family == AF_INET6)) | |
174 | continue; | |
175 | #endif | |
176 | ||
177 | sendto_one(source_p, form_str(RPL_ETRACE), | |
55abcbb2 KB |
178 | me.name, source_p->name, |
179 | IsOper(target_p) ? "Oper" : "User", | |
212380e3 AC |
180 | get_client_class(target_p), |
181 | target_p->name, target_p->username, target_p->host, | |
182 | show_ip(source_p, target_p) ? target_p->sockhost : "255.255.255.255", | |
183 | target_p->info); | |
184 | } | |
185 | ||
186 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
187 | } | |
188 | ||
189 | static void | |
190 | do_etrace_full(struct Client *source_p) | |
191 | { | |
5b96d9a6 | 192 | rb_dlink_node *ptr; |
212380e3 | 193 | |
5b96d9a6 | 194 | RB_DLINK_FOREACH(ptr, lclient_list.head) |
212380e3 AC |
195 | { |
196 | do_single_etrace(source_p, ptr->data); | |
197 | } | |
198 | ||
199 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
200 | } | |
201 | ||
202 | /* | |
203 | * do_single_etrace - searches local clients and displays those matching | |
204 | * a pattern | |
205 | * input - source client, target client | |
206 | * output - etrace results | |
207 | * side effects - etrace results are displayed | |
208 | */ | |
209 | static void | |
210 | do_single_etrace(struct Client *source_p, struct Client *target_p) | |
211 | { | |
212 | /* note, we hide fullcaps for spoofed users, as mirc can often | |
213 | * advertise its internal ip address in the field --fl | |
214 | */ | |
215 | if(!show_ip(source_p, target_p)) | |
216 | sendto_one(source_p, form_str(RPL_ETRACEFULL), | |
55abcbb2 | 217 | me.name, source_p->name, |
212380e3 AC |
218 | IsOper(target_p) ? "Oper" : "User", |
219 | get_client_class(target_p), | |
55abcbb2 | 220 | target_p->name, target_p->username, target_p->host, |
212380e3 AC |
221 | "255.255.255.255", "<hidden> <hidden>", target_p->info); |
222 | else | |
223 | sendto_one(source_p, form_str(RPL_ETRACEFULL), | |
55abcbb2 | 224 | me.name, source_p->name, |
212380e3 AC |
225 | IsOper(target_p) ? "Oper" : "User", |
226 | get_client_class(target_p), | |
55abcbb2 | 227 | target_p->name, target_p->username, |
212380e3 AC |
228 | target_p->host, target_p->sockhost, |
229 | target_p->localClient->fullcaps, target_p->info); | |
230 | } | |
231 | ||
232 | static int | |
428ca87b | 233 | m_chantrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
234 | { |
235 | struct Client *target_p; | |
236 | struct Channel *chptr; | |
237 | struct membership *msptr; | |
238 | const char *sockhost; | |
239 | const char *name; | |
5b96d9a6 | 240 | rb_dlink_node *ptr; |
212380e3 AC |
241 | int operspy = 0; |
242 | ||
243 | name = parv[1]; | |
244 | ||
245 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
246 | { | |
247 | name++; | |
248 | operspy = 1; | |
249 | ||
250 | if(EmptyString(name)) | |
251 | { | |
252 | sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), | |
253 | me.name, source_p->name, "CHANTRACE"); | |
254 | return 0; | |
255 | } | |
256 | } | |
257 | ||
258 | if((chptr = find_channel(name)) == NULL) | |
259 | { | |
260 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), | |
261 | name); | |
262 | return 0; | |
263 | } | |
264 | ||
265 | /* dont report operspys for nonexistant channels. */ | |
266 | if(operspy) | |
267 | report_operspy(source_p, "CHANTRACE", chptr->chname); | |
268 | ||
269 | if(!operspy && !IsMember(client_p, chptr)) | |
270 | { | |
271 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, form_str(ERR_NOTONCHANNEL), | |
272 | chptr->chname); | |
273 | return 0; | |
274 | } | |
275 | ||
5b96d9a6 | 276 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
277 | { |
278 | msptr = ptr->data; | |
279 | target_p = msptr->client_p; | |
280 | ||
281 | if(EmptyString(target_p->sockhost)) | |
282 | sockhost = empty_sockhost; | |
283 | else if(!show_ip(source_p, target_p)) | |
284 | sockhost = spoofed_sockhost; | |
285 | else | |
286 | sockhost = target_p->sockhost; | |
287 | ||
288 | sendto_one(source_p, form_str(RPL_ETRACE), | |
55abcbb2 | 289 | me.name, source_p->name, |
212380e3 AC |
290 | IsOper(target_p) ? "Oper" : "User", |
291 | /* class field -- pretend its server.. */ | |
292 | target_p->servptr->name, | |
293 | target_p->name, target_p->username, target_p->host, | |
294 | sockhost, target_p->info); | |
295 | } | |
296 | ||
297 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); | |
298 | return 0; | |
299 | } | |
300 | ||
301 | static void | |
5b96d9a6 | 302 | match_masktrace(struct Client *source_p, rb_dlink_list *list, |
212380e3 AC |
303 | const char *username, const char *hostname, const char *name, |
304 | const char *gecos) | |
305 | { | |
306 | struct Client *target_p; | |
5b96d9a6 | 307 | rb_dlink_node *ptr; |
55abcbb2 KB |
308 | const char *sockhost; |
309 | ||
5b96d9a6 | 310 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
311 | { |
312 | target_p = ptr->data; | |
313 | if(!IsPerson(target_p)) | |
314 | continue; | |
55abcbb2 | 315 | |
212380e3 AC |
316 | if(EmptyString(target_p->sockhost)) |
317 | sockhost = empty_sockhost; | |
318 | else if(!show_ip(source_p, target_p)) | |
319 | sockhost = spoofed_sockhost; | |
320 | else | |
321 | sockhost = target_p->sockhost; | |
322 | ||
323 | if(match(username, target_p->username) && | |
324 | (match(hostname, target_p->host) || | |
325 | match(hostname, target_p->orighost) || | |
326 | match(hostname, sockhost) || match_ips(hostname, sockhost))) | |
327 | { | |
328 | if(name != NULL && !match(name, target_p->name)) | |
329 | continue; | |
330 | ||
39b23540 | 331 | if(gecos != NULL && !match_esc(gecos, target_p->info)) |
212380e3 | 332 | continue; |
55abcbb2 | 333 | |
212380e3 | 334 | sendto_one(source_p, form_str(RPL_ETRACE), |
55abcbb2 | 335 | me.name, source_p->name, |
212380e3 AC |
336 | IsOper(target_p) ? "Oper" : "User", |
337 | /* class field -- pretend its server.. */ | |
338 | target_p->servptr->name, | |
339 | target_p->name, target_p->username, target_p->host, | |
340 | sockhost, target_p->info); | |
341 | } | |
342 | } | |
343 | } | |
344 | ||
345 | static int | |
428ca87b | 346 | mo_masktrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, |
212380e3 AC |
347 | const char *parv[]) |
348 | { | |
349 | char *name, *username, *hostname, *gecos; | |
350 | const char *mask; | |
351 | int operspy = 0; | |
352 | ||
55abcbb2 KB |
353 | mask = parv[1]; |
354 | name = LOCAL_COPY(parv[1]); | |
212380e3 AC |
355 | collapse(name); |
356 | ||
357 | if(IsOperSpy(source_p) && parv[1][0] == '!') | |
358 | { | |
359 | name++; | |
360 | mask++; | |
361 | operspy = 1; | |
55abcbb2 KB |
362 | } |
363 | ||
212380e3 AC |
364 | if(parc > 2 && !EmptyString(parv[2])) |
365 | { | |
366 | gecos = LOCAL_COPY(parv[2]); | |
367 | collapse_esc(gecos); | |
368 | } else | |
369 | gecos = NULL; | |
55abcbb2 | 370 | |
212380e3 AC |
371 | |
372 | if((hostname = strchr(name, '@')) == NULL) | |
373 | { | |
5366977b | 374 | sendto_one_notice(source_p, ":Invalid parameters"); |
212380e3 AC |
375 | return 0; |
376 | } | |
377 | ||
378 | *hostname++ = '\0'; | |
55abcbb2 | 379 | |
212380e3 AC |
380 | if((username = strchr(name, '!')) == NULL) |
381 | { | |
382 | username = name; | |
383 | name = NULL; | |
384 | } else | |
385 | *username++ = '\0'; | |
386 | ||
387 | if(EmptyString(username) || EmptyString(hostname)) | |
388 | { | |
5366977b | 389 | sendto_one_notice(source_p, ":Invalid parameters"); |
212380e3 AC |
390 | return 0; |
391 | } | |
55abcbb2 | 392 | |
212380e3 AC |
393 | if(operspy) { |
394 | if (!ConfigFileEntry.operspy_dont_care_user_info) | |
395 | { | |
396 | char buf[512]; | |
f427c8b0 | 397 | rb_strlcpy(buf, mask, sizeof(buf)); |
212380e3 | 398 | if(!EmptyString(gecos)) { |
1f9de103 VY |
399 | rb_strlcat(buf, " ", sizeof(buf)); |
400 | rb_strlcat(buf, gecos, sizeof(buf)); | |
55abcbb2 | 401 | } |
212380e3 | 402 | |
55abcbb2 | 403 | report_operspy(source_p, "MASKTRACE", buf); |
212380e3 | 404 | } |
55abcbb2 | 405 | match_masktrace(source_p, &global_client_list, username, hostname, name, gecos); |
212380e3 AC |
406 | } else |
407 | match_masktrace(source_p, &lclient_list, username, hostname, name, gecos); | |
408 | ||
55abcbb2 | 409 | sendto_one_numeric(source_p, RPL_ENDOFTRACE, form_str(RPL_ENDOFTRACE), me.name); |
212380e3 AC |
410 | return 0; |
411 | } |