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.
32 * $Id: m_etrace.c 3161 2007-01-25 07:23:01Z nenolod $
47 #include "s_newconf.h"
53 #include "supported.h"
55 static int mo_etrace(struct Client
*, struct Client
*, int, const char **);
56 static int me_etrace(struct Client
*, struct Client
*, int, const char **);
57 static int m_chantrace(struct Client
*, struct Client
*, int, const char **);
58 static int mo_masktrace(struct Client
*, struct Client
*, int, const char **);
60 struct Message etrace_msgtab
= {
61 "ETRACE", 0, 0, 0, MFLG_SLOW
,
62 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_etrace
, 0}, {mo_etrace
, 0}}
64 struct Message chantrace_msgtab
= {
65 "CHANTRACE", 0, 0, 0, MFLG_SLOW
,
66 {mg_ignore
, {m_chantrace
, 2}, mg_ignore
, mg_ignore
, mg_ignore
, {m_chantrace
, 2}}
68 struct Message masktrace_msgtab
= {
69 "MASKTRACE", 0, 0, 0, MFLG_SLOW
,
70 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_masktrace
, 2}}
76 add_isupport("ETRACE", isupport_string
, "");
84 delete_isupport("ETRACE");
87 mapi_clist_av1 etrace_clist
[] = { &etrace_msgtab
, &chantrace_msgtab
, &masktrace_msgtab
, NULL
};
88 DECLARE_MODULE_AV1(etrace
, _modinit
, _moddeinit
, etrace_clist
, NULL
, NULL
, "$Revision: 3161 $");
90 static void do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
);
91 static void do_etrace_full(struct Client
*source_p
);
92 static void do_single_etrace(struct Client
*source_p
, struct Client
*target_p
);
94 static const char *empty_sockhost
= "255.255.255.255";
95 static const char *spoofed_sockhost
= "0";
99 * parv[1] = options [or target]
103 mo_etrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
105 if(parc
> 1 && !EmptyString(parv
[1]))
107 if(!irccmp(parv
[1], "-full"))
108 do_etrace_full(source_p
);
110 else if(!irccmp(parv
[1], "-v6"))
111 do_etrace(source_p
, 0, 1);
112 else if(!irccmp(parv
[1], "-v4"))
113 do_etrace(source_p
, 1, 0);
117 struct Client
*target_p
= find_named_person(parv
[1]);
121 if(!MyClient(target_p
))
122 sendto_one(target_p
, ":%s ENCAP %s ETRACE %s",
123 get_id(source_p
, target_p
),
124 target_p
->servptr
->name
,
125 get_id(target_p
, target_p
));
127 do_single_etrace(source_p
, target_p
);
130 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
131 form_str(ERR_NOSUCHNICK
), parv
[1]);
135 do_etrace(source_p
, 1, 1);
141 me_etrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
143 struct Client
*target_p
;
145 if(!IsOper(source_p
) || parc
< 2 || EmptyString(parv
[1]))
148 /* we cant etrace remote clients.. we shouldnt even get sent them */
149 if((target_p
= find_person(parv
[1])) && MyClient(target_p
))
150 do_single_etrace(source_p
, target_p
);
152 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
),
153 target_p
? target_p
->name
: parv
[1]);
159 do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
)
161 struct Client
*target_p
;
164 /* report all direct connections */
165 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
167 target_p
= ptr
->data
;
170 if((!ipv4
&& target_p
->localClient
->ip
.ss_family
== AF_INET
) ||
171 (!ipv6
&& target_p
->localClient
->ip
.ss_family
== AF_INET6
))
175 sendto_one(source_p
, form_str(RPL_ETRACE
),
176 me
.name
, source_p
->name
,
177 IsOper(target_p
) ? "Oper" : "User",
178 get_client_class(target_p
),
179 target_p
->name
, target_p
->username
, target_p
->host
,
180 show_ip(source_p
, target_p
) ? target_p
->sockhost
: "255.255.255.255",
184 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
188 do_etrace_full(struct Client
*source_p
)
192 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
194 do_single_etrace(source_p
, ptr
->data
);
197 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
201 * do_single_etrace - searches local clients and displays those matching
203 * input - source client, target client
204 * output - etrace results
205 * side effects - etrace results are displayed
208 do_single_etrace(struct Client
*source_p
, struct Client
*target_p
)
210 /* note, we hide fullcaps for spoofed users, as mirc can often
211 * advertise its internal ip address in the field --fl
213 if(!show_ip(source_p
, target_p
))
214 sendto_one(source_p
, form_str(RPL_ETRACEFULL
),
215 me
.name
, source_p
->name
,
216 IsOper(target_p
) ? "Oper" : "User",
217 get_client_class(target_p
),
218 target_p
->name
, target_p
->username
, target_p
->host
,
219 "255.255.255.255", "<hidden> <hidden>", target_p
->info
);
221 sendto_one(source_p
, form_str(RPL_ETRACEFULL
),
222 me
.name
, source_p
->name
,
223 IsOper(target_p
) ? "Oper" : "User",
224 get_client_class(target_p
),
225 target_p
->name
, target_p
->username
,
226 target_p
->host
, target_p
->sockhost
,
227 target_p
->localClient
->fullcaps
, target_p
->info
);
231 m_chantrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
233 struct Client
*target_p
;
234 struct Channel
*chptr
;
235 struct membership
*msptr
;
236 const char *sockhost
;
243 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
248 if(EmptyString(name
))
250 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
251 me
.name
, source_p
->name
, "CHANTRACE");
256 if((chptr
= find_channel(name
)) == NULL
)
258 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
, form_str(ERR_NOSUCHCHANNEL
),
263 /* dont report operspys for nonexistant channels. */
265 report_operspy(source_p
, "CHANTRACE", chptr
->chname
);
267 if(!operspy
&& !IsMember(client_p
, chptr
))
269 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
, form_str(ERR_NOTONCHANNEL
),
274 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
277 target_p
= msptr
->client_p
;
279 if(EmptyString(target_p
->sockhost
))
280 sockhost
= empty_sockhost
;
281 else if(!show_ip(source_p
, target_p
))
282 sockhost
= spoofed_sockhost
;
284 sockhost
= target_p
->sockhost
;
286 sendto_one(source_p
, form_str(RPL_ETRACE
),
287 me
.name
, source_p
->name
,
288 IsOper(target_p
) ? "Oper" : "User",
289 /* class field -- pretend its server.. */
290 target_p
->servptr
->name
,
291 target_p
->name
, target_p
->username
, target_p
->host
,
292 sockhost
, target_p
->info
);
295 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
300 match_masktrace(struct Client
*source_p
, rb_dlink_list
*list
,
301 const char *username
, const char *hostname
, const char *name
,
304 struct Client
*target_p
;
306 const char *sockhost
;
308 RB_DLINK_FOREACH(ptr
, list
->head
)
310 target_p
= ptr
->data
;
311 if(!IsPerson(target_p
))
314 if(EmptyString(target_p
->sockhost
))
315 sockhost
= empty_sockhost
;
316 else if(!show_ip(source_p
, target_p
))
317 sockhost
= spoofed_sockhost
;
319 sockhost
= target_p
->sockhost
;
321 if(match(username
, target_p
->username
) &&
322 (match(hostname
, target_p
->host
) ||
323 match(hostname
, target_p
->orighost
) ||
324 match(hostname
, sockhost
) || match_ips(hostname
, sockhost
)))
326 if(name
!= NULL
&& !match(name
, target_p
->name
))
329 if(gecos
!= NULL
&& !match_esc(gecos
, target_p
->info
))
332 sendto_one(source_p
, form_str(RPL_ETRACE
),
333 me
.name
, source_p
->name
,
334 IsOper(target_p
) ? "Oper" : "User",
335 /* class field -- pretend its server.. */
336 target_p
->servptr
->name
,
337 target_p
->name
, target_p
->username
, target_p
->host
,
338 sockhost
, target_p
->info
);
344 mo_masktrace(struct Client
*client_p
, struct Client
*source_p
, int parc
,
347 char *name
, *username
, *hostname
, *gecos
;
352 name
= LOCAL_COPY(parv
[1]);
355 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
362 if(parc
> 2 && !EmptyString(parv
[2]))
364 gecos
= LOCAL_COPY(parv
[2]);
370 if((hostname
= strchr(name
, '@')) == NULL
)
372 sendto_one_notice(source_p
, ":Invalid parameters");
378 if((username
= strchr(name
, '!')) == NULL
)
385 if(EmptyString(username
) || EmptyString(hostname
))
387 sendto_one_notice(source_p
, ":Invalid parameters");
392 if (!ConfigFileEntry
.operspy_dont_care_user_info
)
395 rb_strlcpy(buf
, mask
, sizeof(buf
));
396 if(!EmptyString(gecos
)) {
397 rb_strlcat(buf
, " ", sizeof(buf
));
398 rb_strlcat(buf
, gecos
, sizeof(buf
));
401 report_operspy(source_p
, "MASKTRACE", buf
);
403 match_masktrace(source_p
, &global_client_list
, username
, hostname
, name
, gecos
);
405 match_masktrace(source_p
, &lclient_list
, username
, hostname
, name
, gecos
);
407 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);