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 $
42 #include "irc_string.h"
47 #include "s_newconf.h"
53 static int mo_etrace(struct Client
*, struct Client
*, int, const char **);
54 static int me_etrace(struct Client
*, struct Client
*, int, const char **);
55 static int mo_chantrace(struct Client
*, struct Client
*, int, const char **);
56 static int mo_masktrace(struct Client
*, struct Client
*, int, const char **);
58 struct Message etrace_msgtab
= {
59 "ETRACE", 0, 0, 0, MFLG_SLOW
,
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, MFLG_SLOW
,
64 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_chantrace
, 2}}
66 struct Message masktrace_msgtab
= {
67 "MASKTRACE", 0, 0, 0, MFLG_SLOW
,
68 {mg_ignore
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_masktrace
, 2}}
71 mapi_clist_av1 etrace_clist
[] = { &etrace_msgtab
, &chantrace_msgtab
, &masktrace_msgtab
, NULL
};
72 DECLARE_MODULE_AV1(etrace
, NULL
, NULL
, etrace_clist
, NULL
, NULL
, "$Revision: 3161 $");
74 static void do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
);
75 static void do_etrace_full(struct Client
*source_p
);
76 static void do_single_etrace(struct Client
*source_p
, struct Client
*target_p
);
78 static const char *empty_sockhost
= "255.255.255.255";
79 static const char *spoofed_sockhost
= "0";
83 * parv[0] = sender prefix
84 * parv[1] = options [or target]
88 mo_etrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
90 if(parc
> 1 && !EmptyString(parv
[1]))
92 if(!irccmp(parv
[1], "-full"))
93 do_etrace_full(source_p
);
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);
102 struct Client
*target_p
= find_named_person(parv
[1]);
106 if(!MyClient(target_p
))
107 sendto_one(target_p
, ":%s ENCAP %s ETRACE %s",
108 get_id(source_p
, target_p
),
109 target_p
->servptr
->name
,
110 get_id(target_p
, target_p
));
112 do_single_etrace(source_p
, target_p
);
115 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
116 form_str(ERR_NOSUCHNICK
), parv
[1]);
120 do_etrace(source_p
, 1, 1);
126 me_etrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
128 struct Client
*target_p
;
130 if(!IsOper(source_p
) || parc
< 2 || EmptyString(parv
[1]))
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
);
137 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
),
138 target_p
? target_p
->name
: parv
[1]);
144 do_etrace(struct Client
*source_p
, int ipv4
, int ipv6
)
146 struct Client
*target_p
;
149 /* report all direct connections */
150 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
152 target_p
= ptr
->data
;
155 if((!ipv4
&& target_p
->localClient
->ip
.ss_family
== AF_INET
) ||
156 (!ipv6
&& target_p
->localClient
->ip
.ss_family
== AF_INET6
))
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",
169 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
173 do_etrace_full(struct Client
*source_p
)
177 RB_DLINK_FOREACH(ptr
, lclient_list
.head
)
179 do_single_etrace(source_p
, ptr
->data
);
182 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
186 * do_single_etrace - searches local clients and displays those matching
188 * input - source client, target client
189 * output - etrace results
190 * side effects - etrace results are displayed
193 do_single_etrace(struct Client
*source_p
, struct Client
*target_p
)
195 /* note, we hide fullcaps for spoofed users, as mirc can often
196 * advertise its internal ip address in the field --fl
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
);
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
);
216 mo_chantrace(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
218 struct Client
*target_p
;
219 struct Channel
*chptr
;
220 struct membership
*msptr
;
221 const char *sockhost
;
228 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
233 if(EmptyString(name
))
235 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
236 me
.name
, source_p
->name
, "CHANTRACE");
241 if((chptr
= find_channel(name
)) == NULL
)
243 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
, form_str(ERR_NOSUCHCHANNEL
),
248 /* dont report operspys for nonexistant channels. */
250 report_operspy(source_p
, "CHANTRACE", chptr
->chname
);
252 if(!operspy
&& !IsMember(client_p
, chptr
))
254 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
, form_str(ERR_NOTONCHANNEL
),
259 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
262 target_p
= msptr
->client_p
;
264 if(EmptyString(target_p
->sockhost
))
265 sockhost
= empty_sockhost
;
266 else if(!show_ip(source_p
, target_p
))
267 sockhost
= spoofed_sockhost
;
269 sockhost
= target_p
->sockhost
;
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
);
280 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);
285 match_masktrace(struct Client
*source_p
, rb_dlink_list
*list
,
286 const char *username
, const char *hostname
, const char *name
,
289 struct Client
*target_p
;
291 const char *sockhost
;
292 char *mangle_gecos
= NULL
;
296 if(strstr(gecos
, "\\s"))
298 char *tmp
= LOCAL_COPY(gecos
);
303 if(*orig
== '\\' && *(orig
+ 1) != '\0')
305 if(*(orig
+ 1) == 's')
310 /* otherwise skip that and the escaped
311 * character after it, so we dont mistake
325 mangle_gecos
= LOCAL_COPY(tmp
);
328 mangle_gecos
= LOCAL_COPY(gecos
);
331 RB_DLINK_FOREACH(ptr
, list
->head
)
333 target_p
= ptr
->data
;
334 if(!IsPerson(target_p
))
337 if(EmptyString(target_p
->sockhost
))
338 sockhost
= empty_sockhost
;
339 else if(!show_ip(source_p
, target_p
))
340 sockhost
= spoofed_sockhost
;
342 sockhost
= target_p
->sockhost
;
344 if(match(username
, target_p
->username
) &&
345 (match(hostname
, target_p
->host
) ||
346 match(hostname
, target_p
->orighost
) ||
347 match(hostname
, sockhost
) || match_ips(hostname
, sockhost
)))
349 if(name
!= NULL
&& !match(name
, target_p
->name
))
352 if(mangle_gecos
!= NULL
&& !match_esc(mangle_gecos
, target_p
->info
))
355 sendto_one(source_p
, form_str(RPL_ETRACE
),
356 me
.name
, source_p
->name
,
357 IsOper(target_p
) ? "Oper" : "User",
358 /* class field -- pretend its server.. */
359 target_p
->servptr
->name
,
360 target_p
->name
, target_p
->username
, target_p
->host
,
361 sockhost
, target_p
->info
);
367 mo_masktrace(struct Client
*client_p
, struct Client
*source_p
, int parc
,
370 char *name
, *username
, *hostname
, *gecos
;
375 name
= LOCAL_COPY(parv
[1]);
378 if(IsOperSpy(source_p
) && parv
[1][0] == '!')
385 if(parc
> 2 && !EmptyString(parv
[2]))
387 gecos
= LOCAL_COPY(parv
[2]);
393 if((hostname
= strchr(name
, '@')) == NULL
)
395 sendto_one_notice(source_p
, ":Invalid parameters");
401 if((username
= strchr(name
, '!')) == NULL
)
408 if(EmptyString(username
) || EmptyString(hostname
))
410 sendto_one_notice(source_p
, ":Invalid parameters");
415 if (!ConfigFileEntry
.operspy_dont_care_user_info
)
418 strlcpy(buf
, mask
, sizeof(buf
));
419 if(!EmptyString(gecos
)) {
420 strlcat(buf
, " ", sizeof(buf
));
421 strlcat(buf
, gecos
, sizeof(buf
));
424 report_operspy(source_p
, "MASKTRACE", buf
);
426 match_masktrace(source_p
, &global_client_list
, username
, hostname
, name
, gecos
);
428 match_masktrace(source_p
, &lclient_list
, username
, hostname
, name
, gecos
);
430 sendto_one_numeric(source_p
, RPL_ENDOFTRACE
, form_str(RPL_ENDOFTRACE
), me
.name
);