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