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