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.
45 #include "s_newconf.h"
51 #include "supported.h"
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 **);
58 struct Message etrace_msgtab
= {
60 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_etrace
, 0}, {mo_etrace
, 0}}
62 struct Message chantrace_msgtab
= {
63 "CHANTRACE", 0, 0, 0, 0,
64 {mg_ignore
, {m_chantrace
, 2}, mg_ignore
, mg_ignore
, mg_ignore
, {m_chantrace
, 2}}
66 struct Message masktrace_msgtab
= {
67 "MASKTRACE", 0, 0, 0, 0,
68 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_masktrace
, 2}}
74 add_isupport("ETRACE", isupport_string
, "");
82 delete_isupport("ETRACE");
85 mapi_clist_av1 etrace_clist
[] = { &etrace_msgtab
, &chantrace_msgtab
, &masktrace_msgtab
, NULL
};
86 DECLARE_MODULE_AV2(etrace
, _modinit
, _moddeinit
, etrace_clist
, NULL
, NULL
, NULL
, NULL
, NULL
);
88 static void do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
);
89 static void do_etrace_full(struct Client
*source_p
);
90 static void do_single_etrace(struct Client
*source_p
, struct Client
*target_p
);
92 static const char *empty_sockhost
= "255.255.255.255";
93 static const char *spoofed_sockhost
= "0";
97 * parv[1] = options [or target]
101 mo_etrace(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
103 if(parc
> 1 && !EmptyString(parv
[1]))
105 if(!irccmp(parv
[1], "-full"))
106 do_etrace_full(source_p
);
108 else if(!irccmp(parv
[1], "-v6"))
109 do_etrace(source_p
, 0, 1);
110 else if(!irccmp(parv
[1], "-v4"))
111 do_etrace(source_p
, 1, 0);
115 struct Client
*target_p
= find_named_person(parv
[1]);
119 if(!MyClient(target_p
))
120 sendto_one(target_p
, ":%s ENCAP %s ETRACE %s",
121 get_id(source_p
, target_p
),
122 target_p
->servptr
->name
,
123 get_id(target_p
, target_p
));
125 do_single_etrace(source_p
, target_p
);
128 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
129 form_str(ERR_NOSUCHNICK
), parv
[1]);
133 do_etrace(source_p
, 1, 1);
139 me_etrace(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
141 struct Client
*target_p
;
143 if(!IsOper(source_p
) || parc
< 2 || EmptyString(parv
[1]))
146 /* we cant etrace remote clients.. we shouldnt even get sent them */
147 if((target_p
= find_person(parv
[1])) && MyClient(target_p
))
148 do_single_etrace(source_p
, target_p
);
150 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
),
151 target_p
? target_p
->name
: parv
[1]);
157 do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
)
159 struct Client
*target_p
;
162 /* report all direct connections */
163 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
165 target_p
= ptr
->data
;
168 if((!ipv4
&& target_p
->localClient
->ip
.ss_family
== AF_INET
) ||
169 (!ipv6
&& target_p
->localClient
->ip
.ss_family
== AF_INET6
))
173 sendto_one(source_p
, form_str(RPL_ETRACE
),
174 me
.name
, source_p
->name
,
175 IsOper(target_p
) ? "Oper" : "User",
176 get_client_class(target_p
),
177 target_p
->name
, target_p
->username
, target_p
->host
,
178 show_ip(source_p
, target_p
) ? target_p
->sockhost
: "255.255.255.255",
182 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
186 do_etrace_full(struct Client
*source_p
)
190 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
192 do_single_etrace(source_p
, ptr
->data
);
195 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
199 * do_single_etrace - searches local clients and displays those matching
201 * input - source client, target client
202 * output - etrace results
203 * side effects - etrace results are displayed
206 do_single_etrace(struct Client
*source_p
, struct Client
*target_p
)
208 /* note, we hide fullcaps for spoofed users, as mirc can often
209 * advertise its internal ip address in the field --fl
211 if(!show_ip(source_p
, target_p
))
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
, target_p
->host
,
217 "255.255.255.255", "<hidden> <hidden>", target_p
->info
);
219 sendto_one(source_p
, form_str(RPL_ETRACEFULL
),
220 me
.name
, source_p
->name
,
221 IsOper(target_p
) ? "Oper" : "User",
222 get_client_class(target_p
),
223 target_p
->name
, target_p
->username
,
224 target_p
->host
, target_p
->sockhost
,
225 target_p
->localClient
->fullcaps
, target_p
->info
);
229 m_chantrace(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
231 struct Client
*target_p
;
232 struct Channel
*chptr
;
233 struct membership
*msptr
;
234 const char *sockhost
;
241 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
246 if(EmptyString(name
))
248 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
249 me
.name
, source_p
->name
, "CHANTRACE");
254 if((chptr
= find_channel(name
)) == NULL
)
256 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
, form_str(ERR_NOSUCHCHANNEL
),
261 /* dont report operspys for nonexistant channels. */
263 report_operspy(source_p
, "CHANTRACE", chptr
->chname
);
265 if(!operspy
&& !IsMember(client_p
, chptr
))
267 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
, form_str(ERR_NOTONCHANNEL
),
272 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
275 target_p
= msptr
->client_p
;
277 if(EmptyString(target_p
->sockhost
))
278 sockhost
= empty_sockhost
;
279 else if(!show_ip(source_p
, target_p
))
280 sockhost
= spoofed_sockhost
;
282 sockhost
= target_p
->sockhost
;
284 sendto_one(source_p
, form_str(RPL_ETRACE
),
285 me
.name
, source_p
->name
,
286 IsOper(target_p
) ? "Oper" : "User",
287 /* class field -- pretend its server.. */
288 target_p
->servptr
->name
,
289 target_p
->name
, target_p
->username
, target_p
->host
,
290 sockhost
, target_p
->info
);
293 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
298 match_masktrace(struct Client
*source_p
, rb_dlink_list
*list
,
299 const char *username
, const char *hostname
, const char *name
,
302 struct Client
*target_p
;
304 const char *sockhost
;
306 RB_DLINK_FOREACH(ptr
, list
->head
)
308 target_p
= ptr
->data
;
309 if(!IsPerson(target_p
))
312 if(EmptyString(target_p
->sockhost
))
313 sockhost
= empty_sockhost
;
314 else if(!show_ip(source_p
, target_p
))
315 sockhost
= spoofed_sockhost
;
317 sockhost
= target_p
->sockhost
;
319 if(match(username
, target_p
->username
) &&
320 (match(hostname
, target_p
->host
) ||
321 match(hostname
, target_p
->orighost
) ||
322 match(hostname
, sockhost
) || match_ips(hostname
, sockhost
)))
324 if(name
!= NULL
&& !match(name
, target_p
->name
))
327 if(gecos
!= NULL
&& !match_esc(gecos
, target_p
->info
))
330 sendto_one(source_p
, form_str(RPL_ETRACE
),
331 me
.name
, source_p
->name
,
332 IsOper(target_p
) ? "Oper" : "User",
333 /* class field -- pretend its server.. */
334 target_p
->servptr
->name
,
335 target_p
->name
, target_p
->username
, target_p
->host
,
336 sockhost
, target_p
->info
);
342 mo_masktrace(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
,
345 char *name
, *username
, *hostname
, *gecos
;
350 name
= LOCAL_COPY(parv
[1]);
353 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
360 if(parc
> 2 && !EmptyString(parv
[2]))
362 gecos
= LOCAL_COPY(parv
[2]);
368 if((hostname
= strchr(name
, '@')) == NULL
)
370 sendto_one_notice(source_p
, ":Invalid parameters");
376 if((username
= strchr(name
, '!')) == NULL
)
383 if(EmptyString(username
) || EmptyString(hostname
))
385 sendto_one_notice(source_p
, ":Invalid parameters");
390 if (!ConfigFileEntry
.operspy_dont_care_user_info
)
393 rb_strlcpy(buf
, mask
, sizeof(buf
));
394 if(!EmptyString(gecos
)) {
395 rb_strlcat(buf
, " ", sizeof(buf
));
396 rb_strlcat(buf
, gecos
, sizeof(buf
));
399 report_operspy(source_p
, "MASKTRACE", buf
);
401 match_masktrace(source_p
, &global_client_list
, username
, hostname
, name
, gecos
);
403 match_masktrace(source_p
, &lclient_list
, username
, hostname
, name
, gecos
);
405 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);