2 * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
3 * m_etrace.c: Gives local opers a trace output with added info.
5 * Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk>
6 * Copyright (C) 2002-2005 ircd-ratbox development team
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
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.
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.
40 #include "irc_string.h"
46 #include "s_newconf.h"
52 static int mo_etrace(struct Client
*, struct Client
*, int, const char **);
53 static int me_etrace(struct Client
*, struct Client
*, int, const char **);
54 static int mo_chantrace(struct Client
*, struct Client
*, int, const char **);
55 static int mo_masktrace(struct Client
*, struct Client
*, int, const char **);
57 struct Message etrace_msgtab
= {
58 "ETRACE", 0, 0, 0, MFLG_SLOW
,
59 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_etrace
, 0}, {mo_etrace
, 0}}
61 struct Message chantrace_msgtab
= {
62 "CHANTRACE", 0, 0, 0, MFLG_SLOW
,
63 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_chantrace
, 2}}
65 struct Message masktrace_msgtab
= {
66 "MASKTRACE", 0, 0, 0, MFLG_SLOW
,
67 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_masktrace
, 2}}
70 mapi_clist_av1 etrace_clist
[] = { &etrace_msgtab
, &chantrace_msgtab
, &masktrace_msgtab
, NULL
};
71 DECLARE_MODULE_AV1(etrace
, NULL
, NULL
, etrace_clist
, NULL
, NULL
, "$Revision: 147 $");
73 static void do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
);
74 static void do_etrace_full(struct Client
*source_p
);
75 static void do_single_etrace(struct Client
*source_p
, struct Client
*target_p
);
77 static const char *empty_sockhost
= "255.255.255.255";
78 static const char *spoofed_sockhost
= "0";
82 * parv[0] = sender prefix
83 * parv[1] = options [or target]
87 mo_etrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
89 if(!IsOperRouting(source_p
))
91 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
,
96 if(parc
> 1 && !EmptyString(parv
[1]))
98 if(!irccmp(parv
[1], "-full"))
99 do_etrace_full(source_p
);
101 else if(!irccmp(parv
[1], "-v6"))
102 do_etrace(source_p
, 0, 1);
103 else if(!irccmp(parv
[1], "-v4"))
104 do_etrace(source_p
, 1, 0);
108 struct Client
*target_p
= find_named_person(parv
[1]);
112 if(!MyClient(target_p
))
113 sendto_one(target_p
, ":%s ENCAP %s ETRACE %s",
114 get_id(source_p
, target_p
),
115 target_p
->user
->server
,
116 get_id(target_p
, target_p
));
118 do_single_etrace(source_p
, target_p
);
121 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
122 form_str(ERR_NOSUCHNICK
), parv
[1]);
126 do_etrace(source_p
, 1, 1);
132 me_etrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
134 struct Client
*target_p
;
136 if(!IsOperRouting(source_p
) || parc
< 2 || EmptyString(parv
[1]))
139 /* we cant etrace remote clients.. we shouldnt even get sent them */
140 if((target_p
= find_person(parv
[1])) && MyClient(target_p
))
141 do_single_etrace(source_p
, target_p
);
143 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
),
144 target_p
? target_p
->name
: parv
[1]);
150 do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
)
152 struct Client
*target_p
;
155 /* report all direct connections */
156 DLINK_FOREACH(ptr
, lclient_list
.head
)
158 target_p
= ptr
->data
;
161 if((!ipv4
&& target_p
->localClient
->ip
.ss_family
== AF_INET
) ||
162 (!ipv6
&& target_p
->localClient
->ip
.ss_family
== AF_INET6
))
166 sendto_one(source_p
, form_str(RPL_ETRACE
),
167 me
.name
, source_p
->name
,
168 IsOper(target_p
) ? "Oper" : "User",
169 get_client_class(target_p
),
170 target_p
->name
, target_p
->username
, target_p
->host
,
171 show_ip(source_p
, target_p
) ? target_p
->sockhost
: "255.255.255.255",
175 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
179 do_etrace_full(struct Client
*source_p
)
183 DLINK_FOREACH(ptr
, lclient_list
.head
)
185 do_single_etrace(source_p
, ptr
->data
);
188 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
192 * do_single_etrace - searches local clients and displays those matching
194 * input - source client, target client
195 * output - etrace results
196 * side effects - etrace results are displayed
199 do_single_etrace(struct Client
*source_p
, struct Client
*target_p
)
201 /* note, we hide fullcaps for spoofed users, as mirc can often
202 * advertise its internal ip address in the field --fl
204 if(!show_ip(source_p
, target_p
))
205 sendto_one(source_p
, form_str(RPL_ETRACEFULL
),
206 me
.name
, source_p
->name
,
207 IsOper(target_p
) ? "Oper" : "User",
208 get_client_class(target_p
),
209 target_p
->name
, target_p
->username
, target_p
->host
,
210 "255.255.255.255", "<hidden> <hidden>", target_p
->info
);
212 sendto_one(source_p
, form_str(RPL_ETRACEFULL
),
213 me
.name
, source_p
->name
,
214 IsOper(target_p
) ? "Oper" : "User",
215 get_client_class(target_p
),
216 target_p
->name
, target_p
->username
,
217 target_p
->host
, target_p
->sockhost
,
218 target_p
->localClient
->fullcaps
, target_p
->info
);
222 mo_chantrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
224 struct Client
*target_p
;
225 struct Channel
*chptr
;
226 struct membership
*msptr
;
227 const char *sockhost
;
234 if(IsAuspex(source_p
))
238 if(EmptyString(name
))
240 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
241 me
.name
, source_p
->name
, "CHANTRACE");
246 if((chptr
= find_channel(name
)) == NULL
)
248 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
, form_str(ERR_NOSUCHCHANNEL
),
253 if(!auspex
&& !IsMember(client_p
, chptr
))
255 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
, form_str(ERR_NOTONCHANNEL
),
260 DLINK_FOREACH(ptr
, chptr
->members
.head
)
263 target_p
= msptr
->client_p
;
265 if(EmptyString(target_p
->sockhost
))
266 sockhost
= empty_sockhost
;
267 else if(!show_ip(source_p
, target_p
))
268 sockhost
= spoofed_sockhost
;
270 sockhost
= target_p
->sockhost
;
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
);
281 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
286 match_masktrace(struct Client
*source_p
, dlink_list
*list
,
287 const char *username
, const char *hostname
, const char *name
,
290 struct Client
*target_p
;
292 const char *sockhost
;
293 char *mangle_gecos
= NULL
;
297 if(strstr(gecos
, "\\s"))
299 char *tmp
= LOCAL_COPY(gecos
);
306 if(*(orig
+ 1) == 's')
311 /* otherwise skip that and the escaped
312 * character after it, so we dont mistake
326 mangle_gecos
= LOCAL_COPY(tmp
);
329 mangle_gecos
= LOCAL_COPY(gecos
);
332 DLINK_FOREACH(ptr
, list
->head
)
334 target_p
= ptr
->data
;
335 if(!IsPerson(target_p
))
338 if(EmptyString(target_p
->sockhost
))
339 sockhost
= empty_sockhost
;
340 else if(!show_ip(source_p
, target_p
))
341 sockhost
= spoofed_sockhost
;
343 sockhost
= target_p
->sockhost
;
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
)))
350 if(name
!= NULL
&& !match(name
, target_p
->name
))
353 if(mangle_gecos
!= NULL
&& !match_esc(mangle_gecos
, target_p
->info
))
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
);
368 mo_masktrace(struct Client
*client_p
, struct Client
*source_p
, int parc
,
371 char *name
, *username
, *hostname
, *gecos
;
376 name
= LOCAL_COPY(parv
[1]);
379 if(IsAuspex(source_p
))
384 if(parc
> 2 && !EmptyString(parv
[2]))
386 gecos
= LOCAL_COPY(parv
[2]);
392 if((hostname
= strchr(name
, '@')) == NULL
)
394 sendto_one(source_p
, ":%s NOTICE %s :Invalid parameters", me
.name
, source_p
->name
);
400 if((username
= strchr(name
, '!')) == NULL
)
407 if(EmptyString(username
) || EmptyString(hostname
))
409 sendto_one(source_p
, ":%s NOTICE %s :Invalid parameters", me
.name
, source_p
->name
);
414 match_masktrace(source_p
, &global_client_list
, username
, hostname
, name
, gecos
);
416 match_masktrace(source_p
, &lclient_list
, username
, hostname
, name
, gecos
);
418 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);